<template>
  <div class="cart-box">
    <div @click="showCart" class="count-box">
      <img src="./../../../images/ic_user_cart.png" alt="">
      <span class="cart-count"><p>{{count}}</p></span>
    </div>

    <div @click="toCart" class="buy-now">立即购买</div>
    <div class="price-box">
      <p class="price-mark">总计:</p>
      <p class="price-p">{{price | currency '¥'}}</p>
    </div>

  </div>
</template>
<script>
  import popup from './../../../components/popup/index.vue'
  var LocalStorageUtil = require('./../../../commons/js/LocalStorageUtil')
  export default{
    data(){
      return {
        show: false
      }
    },
    props: {
      price: Number,
      count: Number
    },
    components: {
      popup
    },
    methods: {
      toCart(){
        if (!LocalStorageUtil.getItem("User") || !LocalStorageUtil.getItem("User").id) {
          this.$router.go({path: '/login'})
          return
        }
        this.$emit('to-cart')
      },
      showCart(){
        //this.show = true;
        this.$emit('show-pop-cart');
      }
    }
  }
</script>
<style>
  .cart-box {
    height: 4.5rem;
    width: 100%;
    background: white;
    border-top: 0.1rem solid #EEEEEE;
  }

  .cart-box .count-box {
    float: left;
    height: 100%;
    width: 5rem;
    padding-left: 0.5rem;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    position: relative;
  }

  .cart-box .count-box img {
    height: 4rem;
    width: 4rem;
  }

  .cart-box .count-box .cart-count {
    position: absolute;
    font-size: 1rem;
    height: 2rem;
    width: 2rem;
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    background: orangered;
    border-radius: 50%;
    top: 0.2rem;
    right: 0.2rem;
    color: white;
  }

  .cart-box .buy-now {
    height: 100%;
    padding-left: 2rem;
    padding-right: 2rem;
    line-height: 4.5rem;
    font-size: 1.3rem;
    background: orange;
    text-align: center;
    float: right;
    color: white;
  }

  .cart-box .buy-now:active {
    background: darkorange;
  }

  .cart-box .price-box {
    height: 100%;
    padding-right: 2rem;
    line-height: 4.5rem;
    float: right;
    display: flex;
    font-size: 1.5rem;
  }

  .cart-box .price-box .price-mark {
    color: gray;
    padding-right: 0.8rem;
  }

  .cart-box .price-box .price-p {
    color: red;
  }

</style>
